package com.pda.common.pages.outbill;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.pda.common.R;
import com.pda.common.database.BillInfo;

import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;

public class OutBillAdapter extends BaseAdapter {
    private Context mContext;
    LayoutInflater inflater;
    List<BillInfo> mlists = new ArrayList<BillInfo>();
    private int selectedPosition = -1;

    public void setSelectedPosition(int position) {
        selectedPosition = position;
    }

    public OutBillAdapter(Context context, List<BillInfo> lists) {
        this.mContext = context;
        inflater = LayoutInflater.from(context);
        mlists = lists;
    }

    @Override
    public int getCount() {
        return mlists == null ? 0 : mlists.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_outstore, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tv2.setText(mlists.get(position).getBillCode());
        viewHolder.tv3.setText(mlists.get(position).getDesname());
        if (selectedPosition == position) {
            viewHolder.ll.setBackgroundColor(Color.rgb(0, 181, 250));
        } else {
            viewHolder.ll.setBackgroundColor(Color.WHITE);
        }
        return convertView;
    }


    static
    class ViewHolder {
        @BindView(R.id.tv2)
        TextView tv2;
        @BindView(R.id.tv3)
        TextView tv3;
        @BindView(R.id.ll)
        LinearLayout ll;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}

